<template>
  <div class="app-container">
<!--   <span  style="font-weight: bolder">{{skillBmId}}</span>-->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"  style="margin-top: 20px" label-width="68px">
        <el-form-item label="姓名" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="专业类型" prop="zyType">
          <el-select v-model="queryParams.zyType" placeholder="请选择专业类型" clearable>
            <el-option
              v-for="dict in dict.type.zy_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="学号" prop="studyNo">
          <el-input
            v-model="queryParams.studyNo"
            placeholder="请输入学号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-if="type=='bmcheck'"
            v-hasPermi="['system:skillBmUser:add']"
          >新增</el-button>
        </el-col>
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="success"-->
<!--            plain-->
<!--            icon="el-icon-edit"-->
<!--            size="mini"-->
<!--            :disabled="single"-->
<!--            @click="handleUpdate"-->
<!--          >详情</el-button>-->
<!--        </el-col>-->
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="danger"-->
<!--            plain-->
<!--            icon="el-icon-delete"-->
<!--            size="mini"-->
<!--            :disabled="multiple"-->
<!--            @click="handleDelete"-->
<!--            v-hasPermi="['system:user:remove']"-->
<!--          >删除</el-button>-->
<!--        </el-col>-->
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
        <el-table-column label="序号" type="index" width="60" header-align="center" align="center"></el-table-column>
<!--        <el-table-column label="主键" align="center" prop="id" />-->
        <!--      <el-table-column label="大赛Id" align="center" prop="skillId" />-->

        <el-table-column label="报名批次号" align="center" prop="bmNo"  show-overflow-tooltip />
        <el-table-column label="大赛名称" align="center" prop="skillName"  show-overflow-tooltip />
        <!--      <el-table-column label="大赛报名Id" align="center" prop="skillBmId" />-->
        <el-table-column label="姓名" align="center" prop="name"  show-overflow-tooltip />
        <el-table-column label="学校" align="center" prop="schoolName"   show-overflow-tooltip/>
        <el-table-column label="院系" align="center" prop="xyName"   show-overflow-tooltip/>
        <el-table-column label="专业类型" align="center" prop="zyType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.zy_type" :value="scope.row.zyType"/>
          </template>
        </el-table-column>
        <el-table-column label="学号" align="center" prop="studyNo"    />
        <el-table-column label="成绩" align="center" prop="score"   v-if="type=='pf'  || type=='score'"/>
        <el-table-column label="排名" align="center" prop="rankNo"   v-if="type=='pf'  || type=='score'"/>
        <el-table-column label="获奖等级" align="center" prop="levelType"  v-if="type=='pf'  || type=='score'" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.award_level" :value="scope.row.levelType"/>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-if="type=='bmcheck'"
              v-hasPermi="['system:skillBmUser:remove']"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              v-hasPermi="['system:skillBmUser:detail']"
              @click="detail(scope.row)"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:skillBmUser:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改大赛报名人员信息对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入姓名" />
          </el-form-item>
          <el-form-item label="学校" prop="schoolDeptId">
            <el-select v-model="form.schoolDeptId" placeholder="请选择">
              <el-option
                v-for="dict in schoolList"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="院系" prop="xyDeptId">
            <el-select v-model="form.xyDeptId" placeholder="请选择院系">
              <el-option
                v-for="dict in yxList"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="专业类型" prop="zyType">
            <el-select v-model="form.zyType" placeholder="请选择专业类型">
              <el-option
                v-for="dict in dict.type.zy_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="学号" prop="studyNo">
            <el-input v-model="form.studyNo" placeholder="请输入学号" />
          </el-form-item>
          <el-form-item label="指导老师" prop="teacherName">
            <el-input v-model="form.teacherName" placeholder="请输入指导老师" />
          </el-form-item>
        </el-form>
        <el-form ref="formfj" label-width="120px">
          <el-form-item label="附件信息" prop="ysSm">
            <div>
              <FileUpload
                v-if="open"
                ref="expertRef"
                :disabled="true"
                :bottom-tips="'文件格式必须为\'.doc\',\'.docx\',\'.pdf\',\'.png\',文件大小不超过10M'"
                :businessId="form.id"
                :biz-type="'xqfj001'"
                :limit="5"
                :accept="['.doc','.docx','.pdf','.png']"
                style="margin-left: 20px"
              ></FileUpload>
            </div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm" v-if="flag!='detail'">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>


  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser } from "@/api/business/skillbmuser";
import { getBm, updateWbBm, updateWbBmEdit } from '../../api/business/skillbm'
import { getSelectDeptlist } from '../../api/system/dept'
import { guid } from '../../utils/utils'
import FileUpload from '@/components/fileUpload_new.vue'

export default {
  name: "SillBmUser",
  dicts: ['zy_type','award_level'],
  components: { FileUpload },
  props: {
    skillBmId: {
      type: String,
      default: null
    },
    skillId: {
      type: String,
      default: null
    },
    type: {
      type: String,
      default: null
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      bmno: "",
      // 总条数
      total: 0,
      // 大赛报名人员信息表格数据
      userList: [],
      schoolList: [],
      yxList: [],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openBmXx: false,
      flag:"",
      teacherName:"",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        skillId: null,
        skillBmId: null,
        name: null,
        schoolDeptId: null,
        xyDeptId: null,
        zyType: null,
        studyNo: null,
        source: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
    };
  },
  created() {
    this.getList();
    this.getBmInfo()
    this.getSelectDeptlist()
    this.getSelectYxDeptlist()
  },
  watch: {
    open(val) {
      if(!val){
        // 触发父组件的函数
        this.$emit('getList')
      }

    }
  },
  methods: {
    /** 查询大赛报名人员信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.skillBmId=this.skillBmId
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getSelectDeptlist(){
      var  data={
        deptId:100
      }
      getSelectDeptlist(data).then(response => {
        this.schoolList=response.data
      })

    },
    getSelectYxDeptlist(){
      var  data={
        parentId:100
      }
      getSelectDeptlist(data).then(response => {
        this.yxList=response.data
      })
    },
    getBmInfo() {
      getBm(this.skillBmId).then(response => {
        if(response.data){
          this.teacherName=response.data.teacherName;
        }
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        skillId: this.skillId,
        skillBmId: this.skillBmId,
        name: null,
        schoolDeptId: null,
        bmType:null,
        xyDeptId: null,
        zyType: null,
        studyNo: null,
        source: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        schoolName: null,
        teacherName: null,
        xyName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    detail(row) {
      this.reset();
      this.flag="detail"
      const id = row.id || this.ids
      getUser(id).then(response => {
        this.form = response.data;
        if(this.form.schoolDeptId){
          this.form.schoolDeptId=Number(this.form.schoolDeptId)
        }
        if(this.form.xyDeptId){
          this.form.xyDeptId=Number(this.form.xyDeptId)
        }
        this.open = true;
        this.title = "详情";
      });
    },
    handleAdd() {
      this.reset();
      this.title = "添加大赛报名人员信息";
      let mizId = guid().replace(/-/g, '');
      this.flag="bm"
      this.form.id=mizId
      this.form.bmType="2"
      getBm(this.skillBmId).then(response => {
        if(response.data){
          this.form.teacherName=response.data.teacherName;
        }
        this.open = true;
      })




    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.flag="edit"
      const id = row.id || this.ids
      getUser(id).then(response => {
        this.form = response.data;
        if(this.form.schoolDeptId){
          this.form.schoolDeptId=Number(this.form.schoolDeptId)
        }
        if(this.form.xyDeptId){
          this.form.xyDeptId=Number(this.form.xyDeptId)
        }
        this.open = true;
        this.title = "大赛报名人员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.flag=='bm'){
            updateWbBm(this.form).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
          }
          if(this.flag=='edit'){
            updateWbBmEdit(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
          }
          // if (this.form.id != null) {
          //   updateUser(this.form).then(response => {
          //     this.$modal.msgSuccess("修改成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // } else {
          //   addUser(this.form).then(response => {
          //     this.$modal.msgSuccess("新增成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除大赛报名人员信息编号为"' + ids + '"的数据项？').then(function() {
        return delUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
